package com.exam.Mapper;


import com.exam.Entity.SingleQuestion;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SingleQuestionMapper{
    @Select("select * from single_question where questionId in (select questionId from paper_manage where questionType = 1 and paperId = #{paperId})")
    List<SingleQuestion> findByIdAndType(Integer PaperId);

    @Select("select * from single_question")
    List<SingleQuestion> findAll();

    /**
     * 查询最后一条记录的questionId
     * @return MultiQuestion
     */
    @Select("select questionId from single_question order by questionId desc limit 1")
    SingleQuestion findOnlyQuestionId();

    @Options(useGeneratedKeys = true,keyProperty = "questionId")
    @Insert("insert into single_question(subject,description,answerA,answerB,answerC,answerD,correctAnswer,scores,level,questionType) " +
            "values(#{subject},#{question},#{answerA},#{answerB},#{answerC},#{answerD},#{correctAnswer},#{scores},#{level},#{questionType})")
    int add(SingleQuestion singleQuestion);

    @Select("select questionId from single_question  where subject =#{subject} order by rand() desc limit #{pageNo}")
    List<Integer> findBySubject(String subject,Integer pageNo);

    @Delete("delete from single_question where questionId = #{questionId}")
    int deleteById(Integer questionId);
}
